let myHandler = async function (event, context, callback, logger) {
  var res = new context.HTTPResponse(context.env, {
    "res-type": "context.env",
    "faas-content-type": "json",
  }, "application/json", "200");
  var year;
  if (event.body) {
    var _body = JSON.parse(event.body);
    year = _body.year;
  } else {
    year = event.year;
  }
  var body = {
    result: ''
  };
  body.result = animal(year);
  res.body = body;
  context.callback(res);

  function animal(inputYear) {
    var resultString;
    if (!isNumber(inputYear)) {
      resultString = "input is not a number";
    } else {
      var remainder = inputYear % 12;
      switch (remainder) {
        case 0:
          resultString = "猴";
          break;
        case 1:
          resultString = "鸡";
          break;
        case 2:
          resultString = "狗";
          break;
        case 3:
          resultString = "猪";
          break;
        case 4:
          resultString = "鼠";
          break;
        case 5:
          resultString = "牛";
          break;
        case 6:
          resultString = "虎";
          break;
        case 7:
          resultString = "兔";
          break;
        case 8:
          resultString = "龙";
          break;
        case 9:
          resultString = "蛇";
          break;
        case 10:
          resultString = "马";
          break;
        case 11:
          resultString = "羊";
          break;
        default:
          resultString = "No symbolic Animal";
      }
    }
    return resultString;
  }

  function isNumber(input) {
    if (parseInt(input).toString() === "NaN") {
      return false;
    } else {
      return true;
    }
  }
};

export { myHandler };